/**
 * 此文件根据 scripts/components-page.ejs 生成，不要手动修改
 */
import React from 'react'
import navable from 'docs/Navable'
import MarkDown from 'docs/MarkDown'
<% if (codes.length > 0) { -%>import log from 'doc/utils/log'<% } %>
import locate from 'doc/locate'

import cn from 'doc/pages/components/<%= name %>/cn.md'
import en from 'doc/pages/components/<%= name %>/en.md'

const source = locate(cn, en)
<% const fileReg = /\.[jt]sx?$/ -%>

const examples = [
<% examples.forEach(function (exam, i) { -%>
  {
    name: '<%= exam.path.replace("example-", "").replace(fileReg, "") %>',
    isTs: <%= exam.path.endsWith(".tsx") %>,
    isTest: <%= exam.path.startsWith("test-") %>,
    title: locate(
      '<%- exam.cn.replace(/'/g, '\\\'') %>',
      '<%- exam.en.replace(/'/g, '\\\'') %>'
    ),
    component: require('doc/pages/components/<%= name %>/<%= exam.path %>').default,
    rawText: require('!raw-loader!doc/pages/components/<%= name %>/<%= exam.path %>'),
<% if (exam.path.endsWith(".tsx")) { -%>
    parseTsText: require('!raw-loader<%= process.env.CASE_ENV === 'test' ? '': '!ts-loader' %>!doc/pages/components/<%= name %>/<%= exam.path %>'),
<% } -%>

  },
<% }) -%>
]

<% if (codes.length > 0) { -%>
log.start()
<% codes.forEach(function (code, i) { -%>
log.setType('<%= code.replace(fileReg, "") %>')
require('doc/pages/components/<%= name %>/code-<%= code %>')
<% }) -%>

const logs = log.end()

const codes = {
<% codes.forEach(function (code, i) { -%>
  '<%= code.replace(fileReg, "") %>': {
    text: require('!raw-loader!doc/pages/components/<%= name %>/code-<%= code %>'),
    log: logs['<%= code.replace(fileReg, "") %>'],
  },
<% }) -%>
}
<% } else { -%>
const codes = undefined
<% } -%>

const api = '<%- JSON.stringify(api)%>';

export default navable(props => (
  <MarkDown {...props} codes={codes} source={source} examples={examples} api={api} />
))
